#include "systick.h"
#include "timg.h"

timer_cycle cycle_timer;

uint32_t pulse_index=0;
/*
 * @brief void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
 * @param  定时器句柄
 * @return 无
 * @note   定时器溢出中断处理
 */
void systick_init(void)
{
        if (get_systick() - cycle_timer.timer_1ms >= 1)
        {
            cycle_timer.timer_1ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_10ms >= 10)
        {
            cycle_timer.timer_10ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_20ms >= 20)
        {
            cycle_timer.timer_20ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_30ms >= 30)
        {
            cycle_timer.timer_30ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_50ms >= 50)
        {
            cycle_timer.timer_50ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_100ms >= 100)
        {
            cycle_timer.timer_100ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_200ms >= 200)
        {
            cycle_timer.timer_200ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_500ms >= 500)
        {
            cycle_timer.timer_500ms_flag = 1;
        }
        if (get_systick() - cycle_timer.timer_1000ms >= 1000)
        {
            cycle_timer.timer_1000ms_flag = 1;
        }
}

/*
 * @brief uint8_t Cycle_Timer_1MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时1ms
 */
uint8_t Cycle_Timer_1MS(void)
{
    if (cycle_timer.timer_1ms_flag == 1)
    {
        cycle_timer.timer_1ms = get_systick();
        cycle_timer.timer_1ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_10MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时10ms
 */
uint8_t Cycle_Timer_10MS(void)
{
    if (cycle_timer.timer_10ms_flag == 1)
    {
        cycle_timer.timer_10ms = get_systick();
        cycle_timer.timer_10ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_20MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时20ms
 */
uint8_t Cycle_Timer_20MS(void)
{
    if (cycle_timer.timer_20ms_flag == 1)
    {
        cycle_timer.timer_20ms = get_systick();
        cycle_timer.timer_20ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_30MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时20ms
 */
uint8_t Cycle_Timer_30MS(void)
{
    if (cycle_timer.timer_30ms_flag == 1)
    {
        cycle_timer.timer_30ms = get_systick();
        cycle_timer.timer_30ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_50MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时50ms
 */
uint8_t Cycle_Timer_50MS(void)
{
    if (cycle_timer.timer_50ms_flag == 1)
    {
        cycle_timer.timer_50ms = get_systick();
        cycle_timer.timer_50ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_100MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时50ms
 */
uint8_t Cycle_Timer_100MS(void)
{
    if (cycle_timer.timer_100ms_flag == 1)
    {
        cycle_timer.timer_100ms = get_systick();
        cycle_timer.timer_100ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_200MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时200ms
 */
uint8_t Cycle_Timer_200MS(void)
{
    if (cycle_timer.timer_200ms_flag == 1)
    {
        cycle_timer.timer_200ms = get_systick();
        cycle_timer.timer_200ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_500MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时500ms
 */
uint8_t Cycle_Timer_500MS(void)
{
    if (cycle_timer.timer_500ms_flag == 1)
    {
        cycle_timer.timer_500ms = get_systick();
        cycle_timer.timer_500ms_flag = 0;
        return 1;
    }

    return 0;
}
/*
 * @brief uint8_t Cycle_Timer_1000MS(void)
 * @param  无
 * @return 1 时间已经到达，0 时间没到
 * @note   软件定时1000ms
 */
uint8_t Cycle_Timer_1000MS(void)
{
    if (cycle_timer.timer_1000ms_flag == 1)
    {
        cycle_timer.timer_1000ms = get_systick();
        cycle_timer.timer_1000ms_flag = 0;
        return 1;
    }

    return 0;
}
